import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Request,
  Query,
  Req,
} from '@nestjs/common';
import {
  ApiOperation,
  ApiParam,
  ApiBearerAuth,
  ApiTags,
  ApiOkResponse,
} from '@nestjs/swagger';
import { Public } from '../../auth/decorators/public.decorator';
import { HttpService } from '@nestjs/axios';
import {
  definePermission,
  Perm,
} from '~/modules/auth/decorators/permission.decorator';

import { VarTestService } from './varTest.service';

import { VarTestQueryDto } from './dto/varTest.dto';

export const permissions = definePermission('varTest', {
  LIST: 'list',
  TESTSSE: 'testsse',
  TESTREDIS: 'testRedis',
  GETHTTPDATA: 'getHttpData',
  POSTHTTPDATA: 'postHttpData',
} as const);

@ApiTags('Business - VarTest模块')
@Controller('varTest')
@Public()
export class VarTestController {
  constructor(
    private readonly VarTestService: VarTestService,
    private readonly httpService: HttpService
  ) {}

  //练习包含 - 插入文档 查询文档 更新文档 删除文档  聚合查询  关联查询

  @Post('varAdd')
  @ApiOperation({ summary: '添加数据' })
  varAdd(@Body() body) {
    return this.VarTestService.varAdd(body);
  }

  @Post('varList')
  @ApiOperation({ summary: '查询数据' })
  varList(@Body() dto: VarTestQueryDto, @Req() req) {
    return this.VarTestService.varListByFind(dto, req);
    // return this.VarTestService.varList(dto, req);
  }

  @Get('testsse')
  @ApiOperation({ summary: '测试sse' })
  testsse(@Request() req) {
    return this.VarTestService.testsse();
  }

  @Get('testRedis')
  @ApiOperation({ summary: '测试Redis' })
  testRedis(@Request() req) {
    return this.VarTestService.testRedis();
  }

  // 对接三方接口 请求数据写法
  @Get('getHttpData')
  async getHttpData() {
    return this.VarTestService.getHttpData();
  }

  // 对接三方接口 请求数据写法
  @Get('postHttpData')
  async postHttpData() {
    return this.VarTestService.postHttpData();
  }

  //测试添加操作日志的接口
  @Get('addOperateLog')
  async addOperateLog() {
    return this.VarTestService.addOperateLog();
  }
}
